package com.example.smartgreenhouse.utils;

public class ResponseWrapper<T> {
    private int code;
    private String status;
    private String message;
    private T data;

    // 私有构造器
    private ResponseWrapper(int code, String status, String message, T data) {
        this.code = code;
        this.status = status;
        this.message = message;
        this.data = data;
    }

    // 成功响应（带数据）
    public static <T> ResponseWrapper<T> success(String message, T data) {
        return new ResponseWrapper<>(200, "success", message, data);
    }

    // 成功响应（无数据）
    public static ResponseWrapper<?> success(String message) {
        return new ResponseWrapper<>(200, "success", message, null);
    }

    // 失败响应（自定义状态码）
    public static ResponseWrapper<?> failure(int code, String message) {
        return new ResponseWrapper<>(code, "failure", message, null);
    }

    // 参数错误快捷方法
    public static ResponseWrapper<?> badRequest(String message) {
        return failure(400, message);
    }

    // Getter方法
    public int getCode() { return code; }
    public String getStatus() { return status; }
    public String getMessage() { return message; }
    public T getData() { return data; }
}